function [F1, F11, F2] = C57_CPP_Cross_Day_ER_DeltaT(XDay_ER_Summary)
%% get cross-day ER vs deltaT for C5

T1(:,1) = (extractfield(XDay_ER_Summary.C57_5, 'Date1'))';
T1(:,2) = (extractfield(XDay_ER_Summary.C57_5, 'Date2'))';
T1 = datetime(T1,'InputFormat','yyyy-MM-dd');

for n = 1:size(T1,1)
    deltaT1(n,1) = daysact(T1(n,1),T1(n,2));
end

ER1 (:,1) = extractfield(XDay_ER_Summary.C57_5, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for C6

T2(:,1) = (extractfield(XDay_ER_Summary.C57_6, 'Date1'))';
T2(:,2) = (extractfield(XDay_ER_Summary.C57_6, 'Date2'))';
T2 = datetime(T2,'InputFormat','yyyy-MM-dd');

for n = 1:size(T2,1)
    deltaT2(n,1) = daysact(T2(n,1),T2(n,2));
end

ER2 (:,1) = extractfield(XDay_ER_Summary.C57_6, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for C7

T3(:,1) = (extractfield(XDay_ER_Summary.C57_7, 'Date1'))';
T3(:,2) = (extractfield(XDay_ER_Summary.C57_7, 'Date2'))';
T3 = datetime(T3,'InputFormat','yyyy-MM-dd');

for n = 1:size(T3,1)
    deltaT3(n,1) = daysact(T3(n,1),T3(n,2));
end

ER3 (:,1) = extractfield(XDay_ER_Summary.C57_7, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for C8

T4(:,1) = (extractfield(XDay_ER_Summary.C57_8, 'Date1'))';
T4(:,2) = (extractfield(XDay_ER_Summary.C57_8, 'Date2'))';
T4 = datetime(T4,'InputFormat','yyyy-MM-dd');

for n = 1:size(T4,1)
    deltaT4(n,1) = daysact(T4(n,1),T4(n,2));
end

ER4 (:,1) = extractfield(XDay_ER_Summary.C57_8, 'ER_Corr_Values');


%% linear regression

T_WT = cat(1,deltaT1,deltaT2,deltaT3,deltaT4);
ER_WT = cat(1,ER1,ER2,ER3,ER4);

figure
F1 = fit(T_WT,ER_WT,'poly1');
plot(F1,T_WT,ER_WT,'ob');
xlabel('deltaT (days)')
ylabel('mean(ER correlation)')
set(gca, 'FontSize', 20)
ylim([-0.2,0.6])
xlim([0,55])
legend('off')
set(gca, 'Visible', 'off');

F11 = fitlm(T_WT,ER_WT);

%% Alternatively, exponential regression

figure
F2 = fit(T_WT,ER_WT,'exp1');
plot(F2,T_WT,ER_WT,'^b');
xlabel('deltaT (days)')
ylabel('mean(ER correlation)')
set(gca, 'FontSize', 20)
ylim([-0.2,0.6])
xlim([0,55])
legend('off')
set(gca, 'Visible', 'off');

end